#include <iostream>
#include <deque>
int main(){
    int M,N;
    std::cin>>M>>N;
    std::deque<int> q;
    int num;
    for (int i=0;i<M*N;i++){
        std::cin>>num;
        q.push_back(num);
    }
    int time;
    std::cin>>time;
    for (int i=0;i<time;i++){num=q.back();q.pop_back();q.push_front(num);}
    for (int i=0;i<M;i++){
        for (int j=0;j<N;j++){
        num=q.front();
        q.pop_front();
        std::cout<<num;
        if (j!=N-1) std::cout<<" ";
        }
        if(i!=M-1)std::cout<<std::endl;
    }
    return 0;
}